/**
*	Group: Y1
*	The MouseInput class manages input from the mouse on the various panels
*	@author Jessica Newman
*	@author Mason Kwiat
*/
package lightspeed.Media.Graphics;
import java.awt.event.*;
import javax.swing.*;

public class MouseInput implements MouseMotionListener, MouseListener
{
	/**
	*Initializes WindowManager
	**/
	WindowManager wm=null;
	
	/**
	*	Constructor: creates an instance of MouseInput
	*	@param wm WindowManager - so that WindowManager can handle MouseInput events directly
	*/
	public MouseInput(WindowManager wm)
	{
		this.wm = wm;
	}
	/**
	* Lets the system know what to do when the mouse is held down and dragged
	* @param e MouseEvent to let the system know when the mouse is doing something
	**/
	public void mouseDragged(MouseEvent e){}
	
	/**
	* Lets the system know what to do when the mouse is moved
	* If the mouse is moved over certain coordinates, the BufferedImage in MenuPanel changes to the active image
	* @param e MouseEvent to let the system know when the mouse is doing something
	**/
	public void mouseMoved(MouseEvent e)
	{
		//handle mouseover events for menu panel buttons	
		if (WindowManager.currentPanel == WindowManager.MENU_PANEL)
		{
			WindowManager.menuPanel.paintPanel();
			if(e.getX() > MenuPanel.playX && e.getX() < MenuPanel.playX+240 && e.getY() > MenuPanel.playY && e.getY() < MenuPanel.playY+63)
				MenuPanel.paActive=true;	
			else if(e.getX() > MenuPanel.exitX && e.getX() < MenuPanel.exitX+240 && e.getY() > MenuPanel.exitY && e.getY() < MenuPanel.exitY+63)
				MenuPanel.exActive=true;
			else
			{
				MenuPanel.paActive=false;
				MenuPanel.exActive=false;
			}
		}
	
	}
	/**
	* Lets the system know what to do when the mouse is entered
	* @param e MouseEvent to let the system know when the mouse is doing something
	**/
	public void mouseEntered(MouseEvent e){}
	
	/**
	* Lets the system know what to do when the mouse is exited
	* @param e MouseEvent to let the system know when the mouse is doing something
	**/
	public void mouseExited(MouseEvent e){}
	
	/**
	* Lets the system know what to do when the mouse is released
	* @param e MouseEvent to let the system know when the mouse is doing something
	**/
	public void mouseReleased(MouseEvent e){}

	/**
	* Lets the system know what to do when the mouse is pressed
	* @param e MouseEvent to let the system know when the mouse is doing something
	**/
	public void mousePressed(MouseEvent e){}

	/**
	* Lets the system know what to do when the mouse is clicked
	* If the mouse is clicked within the coordinates of a BufferedImage in MenuPanel, it changes screens to
	* the lobby panel, to credits, or exits the program.
	* @param e MouseEvent to let the system know when the mouse is doing something
	**/
	public void mouseClicked(MouseEvent e)
	{
		if(WindowManager.currentPanel == WindowManager.MENU_PANEL)
		{
			if(MenuPanel.paActive)
				wm.setTopLayer(WindowManager.LOBBY_PANEL);
			if(MenuPanel.exActive)
				System.exit(0);
		}
		else if(WindowManager.currentPanel == WindowManager.LOBBY_PANEL)
		{
			boolean notOnTextField=false;
			if(!(e.getX()>LobbyPanel.ipField_left && e.getX()<LobbyPanel.ipField_left+150 && e.getY()>LobbyPanel.ipField_top && e.getY()<LobbyPanel.ipField_top+20))
			{
				notOnTextField=true;
				wm.requestFocus();
			}
			
		}
	}
}
